package command;

import java.util.HashSet;
import java.util.Iterator;

import model.impl.PassengerImpl;
import DTO.PassengerDTO;

import com.gmail.at.vssabinin.train_transport_system_part1.Protocol;
import com.gmail.at.vssabinin.train_transport_system_part1.ReceivedData;

/**
 * Class represents command interface;
 * It modify passenger info according to information received from administer
 * client. It's possible to change everything but not ID. After operation is 
 * finished it sends OK to administer client.
 */
public class AdminModifyPassengers implements Command {

	private Protocol protocol = new Protocol();

	public void execute(ReceivedData recived) {
		Protocol.Message message = this.protocol.decodeMessage(recived.data);
		@SuppressWarnings("unchecked")
		HashSet<PassengerDTO> passenger = (HashSet<PassengerDTO>) message
				.getObject();
		Iterator<PassengerDTO> iter = passenger.iterator();
		while (iter.hasNext()) {
			(new PassengerImpl()).modifyUniquePassenger((iter.next()));
		}
		Protocol.Message answer = this.protocol.new Message("ok", null);
		recived.server.send(recived.socket,
				this.protocol.createMessage(answer));
	}

}